package com.yyy.bo;
import cn.hutool.core.io.FileUtil;
import com.lark.oapi.Client;
import com.lark.oapi.core.utils.Jsons;
import com.lark.oapi.service.optical_char_recognition.v1.model.*;

import java.io.File;

// SDK 使用文档：https://github.com/larksuite/oapi-sdk-java/tree/v2_main
// 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET.
public class BasicRecognizeImageSample {
	private static String imageBase64Path = FileUtil.readUtf8String(new File("F:\\git\\new\\asdasdas\\src\\main\\resources\\t.txt"));

	public static void main(String arg[]) throws Exception {
		// 构建client
		Client client = Client.newBuilder("cli_a6cfd68e8e7bd00e", "LL6oTDlbT0mPw8usKB1ocdicQnNQuPZM").build();

		// 创建请求对象
		BasicRecognizeImageReq req = BasicRecognizeImageReq.newBuilder()
			.basicRecognizeImageReqBody(BasicRecognizeImageReqBody.newBuilder()
				.image(imageBase64Path)
				.build())
			.build();

		// 发起请求
		BasicRecognizeImageResp resp = client.opticalCharRecognition().image().basicRecognize(req);

		// 处理服务端错误
		if(!resp.success()) {
			System.out.println(String.format("code:%s,msg:%s,reqId:%s", resp.getCode(), resp.getMsg(), resp.getRequestId()));
			return;
		}

		// 业务数据处理
		System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
	}
}
